package com.lsa.letcode.the83.deleteDuplicates;

import com.lsa.letcode.common.ListNode;
/**
 * Definition for singly-linked list.
 * public class ListNode {
 *     int val;
 *     ListNode next;
 *     ListNode(int x) { val = x; }
 * }
 * 1 - 1 - 1 - 2 - 3
 */
public class Solution {
    public ListNode deleteDuplicates(ListNode head) {
    	ListNode n = head;
    	ListNode prev = null;
    	
    	// 1 -> 1-> 2
    	
    	while(n != null) {
    		if (prev != null && prev.val == n.val) {
    			prev.next = n.next;
    		}
    		else {
    			prev = n;
    		}
    		n = n.next;
    	}
    	
    	return head;
    }
}